package bom.service.impl.organization;


import bom.configuration.constant.SystemStaticConst;
import bom.configuration.util.UserInfo;
import bom.dao.organization.RoleAssociateTreeDao;
import bom.dao.organization.TreeDao;
import bom.mapper.TreeMapper;
import bom.pojo.organization.Tree;
import bom.pojo.organization.User;
import bom.service.i.organization.TreeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: Fancyears·Maylos·Malvis
 * @Description:
 * @Date: Created in  2018/11/27 15:17
 * @Modified By:
 */
@Service
@Transactional(rollbackFor = {IllegalArgumentException.class})
public class TreeServiceImpl implements TreeService {
    @Autowired(required = false)
    private TreeDao treeDao;
    @Autowired(required = false)
    private RoleAssociateTreeDao roleAssociateTreeDao;
    @Autowired
    private TreeMapper treeMapper;

    /**
     * 功能描述：删除菜单的数据
     *
     * @param entity 删除对象
     * @return
     * @throws Exception
     */
    @Override
    public boolean delete(Tree entity) throws Exception {
        roleAssociateTreeDao.removeTreeByTreeId(entity);
        return treeDao.delete(entity) > 0 ? true : false;
    }

    /**
     * 功能描述：加载用户的菜单树的数据
     *
     * @param user
     * @return
     */
    public List<Tree> loadUserTree(User user) {
        return treeDao.loadUserTree(user);
    }

    @Override
    public Map<String, Object> mainTree() {
        Map<String, Object> result = new HashMap<String, Object>();
        List<Tree> trees = UserInfo.loadUserTree(this);
        result.put("data", trees);
        result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
        return result;
    }

    @Override
    public Tree get(Tree entity) {
        return null;
    }

    @Override
    public Map<String, Object> loadUserTree() {
        Map<String, Object> result = new HashMap<String, Object>();
        List<Tree> treeList = query(null);
        result.put(SystemStaticConst.RESULT, SystemStaticConst.SUCCESS);
        result.put(SystemStaticConst.MSG, "加载菜单数据成功！");
        result.put("data", treeMapper.treesToTressDTOs(treeList));
        return null;
    }

    public List<Tree> query(Object o) {
        return null;
    }
}